/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufg.inf.si.poo.formula1.GUI;

import br.ufg.inf.si.poo.formula1.Driver.Driver;
import br.ufg.inf.si.poo.formula1.Interface.InterfaceRegister;
import br.ufg.inf.si.poo.formula1.Library.Library;
import br.ufg.inf.si.poo.formula1.ManagementFiles.ManagementFiles;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 * RegisterDriver
 *
 * Versao 1.0
 *
 * Data 20/02/2013
 *
 * @author Igor
 */
public class RegisterDriver extends javax.swing.JInternalFrame implements InterfaceRegister {
    //Atributos
    private Driver driver;
    private Boolean emEdicao; //Valida se esta em modo de edicao ou nao
    private Boolean novo; //Variavel que verifica se clicou no botao de novo registro

    //Construtores
    /**
     * Creates new form FramePadrao
     */
    public RegisterDriver() {
        initComponents();
        this.novo = false;
        clearFields();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelTitulo = new javax.swing.JPanel();
        labelTitulo = new javax.swing.JLabel();
        panelDadosPrincipais = new javax.swing.JPanel();
        panelPilotosCadastrados = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listPilotos = new javax.swing.JList();
        labelNome = new javax.swing.JLabel();
        labelEquipe = new javax.swing.JLabel();
        labelNacionalidade = new javax.swing.JLabel();
        labelPodiums = new javax.swing.JLabel();
        labelPontos = new javax.swing.JLabel();
        labelGrandPrix = new javax.swing.JLabel();
        labelCampeaoMundial = new javax.swing.JLabel();
        labelMelhorPosicaoCorrida = new javax.swing.JLabel();
        labelMelhorPodiumCorrida = new javax.swing.JLabel();
        labelDataNascimento = new javax.swing.JLabel();
        labelLocalNascimento = new javax.swing.JLabel();
        textNome = new javax.swing.JTextField();
        textNacionalidade = new javax.swing.JTextField();
        textLocalNascimento = new javax.swing.JTextField();
        textDataNascimento = new javax.swing.JTextField();
        labelCampoCodigo = new javax.swing.JLabel();
        labelEquipe1 = new javax.swing.JLabel();
        labelPodiums1 = new javax.swing.JLabel();
        labelPontos1 = new javax.swing.JLabel();
        labelGrandPrix1 = new javax.swing.JLabel();
        labelCampeaoMundial1 = new javax.swing.JLabel();
        labelMelhorPosicaoCorrida1 = new javax.swing.JLabel();
        labelMelhorPodiumCorrida1 = new javax.swing.JLabel();
        panelBotoes = new javax.swing.JPanel();
        buttonSalvar = new javax.swing.JButton();
        buttonLimpar = new javax.swing.JButton();
        buttonNovo = new javax.swing.JButton();
        labelCamposObrigatorios = new javax.swing.JLabel();

        setClosable(true);
        setForeground(java.awt.Color.white);
        setIconifiable(true);
        setTitle("Cadastro de Pilotos");
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        panelTitulo.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        labelTitulo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        labelTitulo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelTitulo.setText("Tela utilizada para cadastrar e/ou alterar dados do Piloto (Independente da Temporada)");

        javax.swing.GroupLayout panelTituloLayout = new javax.swing.GroupLayout(panelTitulo);
        panelTitulo.setLayout(panelTituloLayout);
        panelTituloLayout.setHorizontalGroup(
            panelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTituloLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTitulo)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelTituloLayout.setVerticalGroup(
            panelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTituloLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTitulo)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelDadosPrincipais.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "   Dados Principais   ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10), java.awt.Color.black)); // NOI18N

        panelPilotosCadastrados.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "   Pilotos   ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10), java.awt.Color.black)); // NOI18N

        listPilotos.setToolTipText("Lista de pilotos cadastrados");
        listPilotos.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listPilotosValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(listPilotos);

        javax.swing.GroupLayout panelPilotosCadastradosLayout = new javax.swing.GroupLayout(panelPilotosCadastrados);
        panelPilotosCadastrados.setLayout(panelPilotosCadastradosLayout);
        panelPilotosCadastradosLayout.setHorizontalGroup(
            panelPilotosCadastradosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
        );
        panelPilotosCadastradosLayout.setVerticalGroup(
            panelPilotosCadastradosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE)
        );

        labelNome.setText("Nome: *");

        labelEquipe.setText("Equipe:");

        labelNacionalidade.setText("Nacionalidade:");

        labelPodiums.setText("Podiums:");

        labelPontos.setText("Pontos:");

        labelGrandPrix.setText("Grand Prix:");

        labelCampeaoMundial.setText("Campeão Mundial:");

        labelMelhorPosicaoCorrida.setText("Melhor posição em corrida:");

        labelMelhorPodiumCorrida.setText("Melhor podium em corrida:");

        labelDataNascimento.setText("Data de Nascimento:");

        labelLocalNascimento.setText("Local de Nascimento:");

        textNacionalidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textNacionalidadeActionPerformed(evt);
            }
        });

        labelCampoCodigo.setText("Campo código");
        labelCampoCodigo.setToolTipText("Não editar");

        labelEquipe1.setText("Valores");

        labelPodiums1.setText("Valores");

        labelPontos1.setText("Valores");

        labelGrandPrix1.setText("Valores");

        labelCampeaoMundial1.setText("Valores");

        labelMelhorPosicaoCorrida1.setText("Valores");

        labelMelhorPodiumCorrida1.setText("Valores");

        javax.swing.GroupLayout panelDadosPrincipaisLayout = new javax.swing.GroupLayout(panelDadosPrincipais);
        panelDadosPrincipais.setLayout(panelDadosPrincipaisLayout);
        panelDadosPrincipaisLayout.setHorizontalGroup(
            panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelDadosPrincipaisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelNome)
                    .addComponent(labelNacionalidade)
                    .addComponent(labelDataNascimento)
                    .addComponent(labelLocalNascimento)
                    .addComponent(labelPodiums)
                    .addComponent(labelPontos)
                    .addComponent(labelGrandPrix)
                    .addComponent(labelCampeaoMundial)
                    .addComponent(labelMelhorPosicaoCorrida)
                    .addComponent(labelMelhorPodiumCorrida)
                    .addComponent(labelEquipe))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelMelhorPodiumCorrida1)
                    .addComponent(labelMelhorPosicaoCorrida1)
                    .addComponent(labelCampeaoMundial1)
                    .addComponent(labelGrandPrix1)
                    .addComponent(labelPontos1)
                    .addComponent(labelPodiums1)
                    .addComponent(labelEquipe1)
                    .addComponent(textLocalNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textNacionalidade, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textNome, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelCampoCodigo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
                .addComponent(panelPilotosCadastrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        panelDadosPrincipaisLayout.setVerticalGroup(
            panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelPilotosCadastrados, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNome)
                    .addComponent(textNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelCampoCodigo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNacionalidade)
                    .addComponent(textNacionalidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelDataNascimento)
                    .addComponent(textDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelLocalNascimento)
                    .addComponent(textLocalNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(labelEquipe)
                    .addComponent(labelEquipe1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(labelPodiums)
                    .addComponent(labelPodiums1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(labelPontos)
                    .addComponent(labelPontos1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(labelGrandPrix)
                    .addComponent(labelGrandPrix1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(labelCampeaoMundial)
                    .addComponent(labelCampeaoMundial1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(labelMelhorPosicaoCorrida)
                    .addComponent(labelMelhorPosicaoCorrida1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(labelMelhorPodiumCorrida)
                    .addComponent(labelMelhorPodiumCorrida1))
                .addContainerGap(139, Short.MAX_VALUE))
        );

        panelBotoes.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        buttonSalvar.setText("Salvar");
        buttonSalvar.setToolTipText("Clique para salvar os dados digitados");
        buttonSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSalvarActionPerformed(evt);
            }
        });

        buttonLimpar.setText("Limpar");
        buttonLimpar.setToolTipText("Clique para limpar a tela e habilitar um novo registro");
        buttonLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonLimparActionPerformed(evt);
            }
        });

        buttonNovo.setText("Novo");
        buttonNovo.setToolTipText("Clique para cadastrar um novo registro");
        buttonNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNovoActionPerformed(evt);
            }
        });

        labelCamposObrigatorios.setText("Campos marcados com *, são obrigatórios");

        javax.swing.GroupLayout panelBotoesLayout = new javax.swing.GroupLayout(panelBotoes);
        panelBotoes.setLayout(panelBotoesLayout);
        panelBotoesLayout.setHorizontalGroup(
            panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotoesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelCamposObrigatorios)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(buttonNovo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonSalvar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonLimpar)
                .addContainerGap())
        );

        panelBotoesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonLimpar, buttonNovo, buttonSalvar});

        panelBotoesLayout.setVerticalGroup(
            panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotoesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonLimpar)
                    .addComponent(buttonSalvar)
                    .addComponent(buttonNovo)
                    .addComponent(labelCamposObrigatorios))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelDadosPrincipais, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelTitulo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelBotoes, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelDadosPrincipais, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLimparActionPerformed
        // TODO add your handling code here:
        clearFields();
    }//GEN-LAST:event_buttonLimparActionPerformed

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        // TODO add your handling code here:
        clearFields();
    }//GEN-LAST:event_formComponentShown

    private void textNacionalidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textNacionalidadeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textNacionalidadeActionPerformed

    private void listPilotosValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listPilotosValueChanged
        // TODO add your handling code here:
        if(this.listPilotos.getSelectedIndex() != -1){
            Driver driver1 = Library.returnDriver( (String)this.listPilotos.getSelectedValue());
            if(driver1 != null){
                this.driver = driver1;
                this.emEdicao = true;
            }
        }
        dataShowObject();
    }//GEN-LAST:event_listPilotosValueChanged

    private void buttonSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSalvarActionPerformed
        // TODO add your handling code here:
        try{
            checkFields();

            checkValueEntered();

            createObject();

            clearFields();
        }catch(IllegalArgumentException e){
            JOptionPane.showMessageDialog(this, e.getMessage(), "Erro!", JOptionPane.ERROR_MESSAGE);
        }catch(ParseException e){
            JOptionPane.showMessageDialog(this, e.getMessage(), "Erro!", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_buttonSalvarActionPerformed

    private void buttonNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNovoActionPerformed
        // TODO add your handling code here:
        this.novo = true; //Diz para o clearFields() que sera um novo registro
        clearFields();
    }//GEN-LAST:event_buttonNovoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonLimpar;
    private javax.swing.JButton buttonNovo;
    private javax.swing.JButton buttonSalvar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelCampeaoMundial;
    private javax.swing.JLabel labelCampeaoMundial1;
    private javax.swing.JLabel labelCampoCodigo;
    private javax.swing.JLabel labelCamposObrigatorios;
    private javax.swing.JLabel labelDataNascimento;
    private javax.swing.JLabel labelEquipe;
    private javax.swing.JLabel labelEquipe1;
    private javax.swing.JLabel labelGrandPrix;
    private javax.swing.JLabel labelGrandPrix1;
    private javax.swing.JLabel labelLocalNascimento;
    private javax.swing.JLabel labelMelhorPodiumCorrida;
    private javax.swing.JLabel labelMelhorPodiumCorrida1;
    private javax.swing.JLabel labelMelhorPosicaoCorrida;
    private javax.swing.JLabel labelMelhorPosicaoCorrida1;
    private javax.swing.JLabel labelNacionalidade;
    private javax.swing.JLabel labelNome;
    private javax.swing.JLabel labelPodiums;
    private javax.swing.JLabel labelPodiums1;
    private javax.swing.JLabel labelPontos;
    private javax.swing.JLabel labelPontos1;
    private javax.swing.JLabel labelTitulo;
    private javax.swing.JList listPilotos;
    private javax.swing.JPanel panelBotoes;
    private javax.swing.JPanel panelDadosPrincipais;
    private javax.swing.JPanel panelPilotosCadastrados;
    private javax.swing.JPanel panelTitulo;
    private javax.swing.JTextField textDataNascimento;
    private javax.swing.JTextField textLocalNascimento;
    private javax.swing.JTextField textNacionalidade;
    private javax.swing.JTextField textNome;
    // End of variables declaration//GEN-END:variables

    //Metodos reescritos da interface InterfaceRegister
    @Override
    public void dataShowObject() {
        this.textNome.setText(this.driver.getDriverName());
        this.textNacionalidade.setText(this.driver.getNationality());
        this.textDataNascimento.setText(this.driver.getDateBirth());
        this.textLocalNascimento.setText(this.driver.getPlaceBirth());

        if(this.driver.getTeam() != null){
            this.labelEquipe1.setText(this.driver.getTeam().getShortName());
        }else{
            this.labelEquipe1.setText("");
        }
        this.labelPodiums1.setText(""+this.driver.getPodiums());
        this.labelPontos1.setText(""+this.driver.getPoints());
        this.labelGrandPrix1.setText(""+this.driver.getGrandPrixEntered());
        this.labelCampeaoMundial1.setText(""+this.driver.getWorldChampionships());
        this.labelMelhorPosicaoCorrida1.setText(this.driver.getHighestRaceFinish()[0]+" (x"+this.driver.getHighestRaceFinish()[1]+")");
        this.labelMelhorPodiumCorrida1.setText(this.driver.getHighestGridPosition()[0]+" (x"+this.driver.getHighestGridPosition()[1]+")");

        Library.indexedListDrivers(this.listPilotos, FrameMain.getDrivers(), null, false);
    }

    @Override
    public void checkFields() throws IllegalArgumentException {
        if(this.textNome.getText().equals("")) {
            throw new IllegalArgumentException("Campos obrigatórios estão vazios.");
        }
    }

    @Override
    public void checkValueEntered() throws IllegalArgumentException, ParseException {
        //Data
        try{
            DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
            Date data = (java.util.Date) formatter.parse(this.textDataNascimento.getText());
        }catch(ParseException e){
            throw new ParseException("Valor inválido de Data.", 0);
        }
    }

    @Override
    public void createObject() throws IllegalArgumentException {
        //Se nao estiver em modo de edicao entao adiciona, pois eh um novo Objeto, caso contrario apenas alterara
        if (!this.emEdicao) {
            if(Library.returnCircuit(this.textNome.getText()) != null){
                throw new IllegalArgumentException("Piloto com 'Nome' "+this.textNome.getText()+" já cadastrado.");
            }
            this.driver.setDriverName(this.textNome.getText());
            FrameMain.setDrivers(this.driver);
        }

        this.driver.setNationality(this.textNacionalidade.getText());
        this.driver.setDateBirth(this.textDataNascimento.getText());
        this.driver.setPlaceBirth(this.textLocalNascimento.getText());

        ManagementFiles.writeDriver(FrameMain.getDrivers());
    }

    @Override
    public void clearFields(){
        this.driver = new Driver();
        this.emEdicao = false;

        if(!this.novo){
            this.listPilotos.setSelectedIndex(0);
        }
        this.novo = false;

        dataShowObject();
        Library.indexedListDrivers(this.listPilotos, FrameMain.getDrivers(), null, false);
    }
}
